<template>
  <div class="focusNews">
    <!--    头部-->
    <div class="top">
      <div class="top_title">今日要闻</div>
      <div class="top_time">{{now_time}}</div>
    </div>

    <!--    内容-->
    <ul class="news_title">
      <li v-for="item in todayNews" :key="item._id">
        <router-link :to="`/newsDetail?id=${item._id}`">{{item.title}}</router-link>
      </li>
    </ul>
  </div>
</template>

<script>
  import {mapState} from 'vuex'
  import moment from 'moment'
  moment.locale('zh-cn') //设置时区

  export default {
    name: "FocusNews",
    data(){
      return {
        now_time:moment().format('YYYY-MM-DD HH:mm:ss dddd')
      }
    },
    methods: {
      getTodayNews() {
        this.$store.dispatch('getTodayNews')
      }
    },
    created() {
      this.getTodayNews()
    },
    computed: {
      ...mapState(['todayNews'])
    },
    mounted() {
      const timer = setInterval(() =>{
        this.now_time=moment().format('YYYY-MM-DD HH:mm:ss dddd')
      },1000);
      this.$once('hooK:beforeDestroy',() => {
        clearInterval(timer)
      })
    }
  }
</script>

<style scoped lang="less">
  .focusNews {
    width: 100%;

    .top {
      border-bottom: 1px solid #999;
      display: flex;
      justify-content: space-between;

      .top_title {
        font-size: 25px;
        padding: 20px 0;
        height: 100%;
        color: #5184EB;
        font-weight: bold;
        border-bottom: 5px #5184EB solid;
      }

      .top_time {
        padding: 20px;
        margin-top: 10px;
        font-size: 16px;
      }
    }

    .news_title {
      border-bottom: 1px solid #999;

      li {
        margin: 30px 0;
        font-size: 25px;
      }
      li:hover a{
        color: #5184EB;
      }
    }
  }

</style>